#include <REGX52.H>
#include "Delayxms.h"
#include "LCD1602.h"
#include "Timer0.h"


unsigned char Sec,Min,Hour;//这里可以赋初始值

void main(){
	LCD_Init();
	Timer0Init();
	
	LCD_ShowString(1,1,"Clock:");
	
	while(1){
		LCD_ShowNum(2,1,Hour,2);
		LCD_ShowString(2,3,":");
		LCD_ShowNum(2,4,Min,2);
		LCD_ShowString(2,6,":");
		LCD_ShowNum(2,7,Sec,2);
	
	}
}


void Timer0_Routine() interrupt 1	//interrupt是一个关键字
	{
	static unsigned int T0Count = 0;
	T0Count++;
		
	//秒数计时	
	if (T0Count >= 1000){
		T0Count = 0;
		//
		Sec++;
		if(Sec >= 60){
			Sec = 0;
			Min++;
			if(Min >= 60){
				Min = 0;
				Hour++;
				if(Hour >= 24){
				Hour = 0;
				}
			}
		}
	}
	TL0 = 0x66;		//设置定时初始值
	TH0 = 0xFC;		//设置定时初始值
	
//	//然后计数器溢出由65535--> 0  而不是我们想要的从64535开始计时,所以
//	//重新赋初值
//	TH0 = 64535 / 256;//低8位的取值
//	TL0 = 64535 % 256;//高8位的取值

}
